package com.ruoyi.stock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.domain.StockBaseinfo;
import com.ruoyi.stock.service.IStockBaseinfoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 基本信息Controller
 * 
 * @author xxb
 * @date 2024-12-30
 */
@RestController
@RequestMapping("/stock/stockbaseinfo")
@Api( tags = "平台设置")
public class StockBaseinfoController extends BaseController
{
    @Autowired
    private IStockBaseinfoService stockBaseinfoService;

    /**
     * 查询基本信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(StockBaseinfo stockBaseinfo)
    {
        startPage();
        List<StockBaseinfo> list = stockBaseinfoService.selectStockBaseinfoList(stockBaseinfo);
        return getDataTable(list);
    }

    /**
     * 导出基本信息列表
     */
    @Log(title = "基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockBaseinfo stockBaseinfo)
    {
        List<StockBaseinfo> list = stockBaseinfoService.selectStockBaseinfoList(stockBaseinfo);
        ExcelUtil<StockBaseinfo> util = new ExcelUtil<StockBaseinfo>(StockBaseinfo.class);
        util.exportExcel(response, list, "基本信息数据");
    }

    /**
     * 获取基本信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stockBaseinfoService.selectStockBaseinfoById(id));
    }

    /**
     * 新增基本信息
     */
    @Log(title = "基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockBaseinfo stockBaseinfo)
    {
        return toAjax(stockBaseinfoService.insertStockBaseinfo(stockBaseinfo));
    }

    /**
     * 修改基本信息
     */
    @Log(title = "基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockBaseinfo stockBaseinfo)
    {
        return toAjax(stockBaseinfoService.updateStockBaseinfo(stockBaseinfo));
    }

    /**
     * 删除基本信息
     */
    @Log(title = "基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stockBaseinfoService.deleteStockBaseinfoByIds(ids));
    }
}
